package com.shanzmoo.db.personnel.entity.dto;

import com.alibaba.fastjson.JSON;
import com.shanzmoo.base.constant.RegularExpression;
import com.shanzmoo.db.personnel.entity.MemberInfoEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 客户信息更新对象
 *
 * @author: Gzhao 2020/12/18
 */
@Data
@ApiModel("客户信息更新对象")
public class MemberInfoUpdateDto implements Serializable {

    private static final long serialVersionUID = 1758L;

    @NotNull(message = "客户ID不允许为空")
    @ApiModelProperty("客户ID")
    private Integer id;

    @NotBlank(message = "客户名称不允许为空")
    @ApiModelProperty("客户名称")
    private String name;

    @NotBlank(message = "公司名称不允许为空")
    @ApiModelProperty("公司名称")
    private String company;

    @NotBlank(message = "公司联系人不允许为空")
    @ApiModelProperty("公司联系人")
    private String contact;

    @Pattern(regexp = RegularExpression.MOBILE, message = "请输入正确的手机号")
    @NotBlank(message = "手机号不允许为空")
    @ApiModelProperty("手机号")
    private String mobile;

    @NotNull(message = "公司所在省市区Id不允许为空")
    @ApiModelProperty("公司所在省市区Id")
    private Integer district;

    @NotBlank(message = "公司详细地址不允许为空")
    @ApiModelProperty("公司详细地址")
    private String address;

    @NotNull(message = "结算方式不允许为空")
    @ApiModelProperty("结算方式（是否月结）：false-否，true-是")
    private Boolean monthly;

    @Min(value = 0, message = "折扣必须小于0")
    @Max(value = 1, message = "折扣不允许超过1")
    @NotNull(message = "折扣不允许为空")
    @ApiModelProperty("折扣")
    private BigDecimal discount;

    @ApiModelProperty("备注")
    private String remark;

    public MemberInfoEntity convert(MemberInfoEntity old) {
        MemberInfoEntity memberInfo = JSON.parseObject(JSON.toJSONString(this), MemberInfoEntity.class);
        memberInfo.setType(old.getType());

        return memberInfo;
    }
}
